Repository navigation
perf(studio-server): preview steps skip the page parse when a tag scan answers - #7092
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Verdict: APPROVE · 0 blocker · 0 important · 0 nits · head 5a500783
All three early returns give the same result as the parse they skip. CI was still running when I reviewed, with nothing failing.
Scope
addScenePartsManifest: I confirmed with linkedom 0.18.15 that[data-hf-scene]does not matchDATA-HF-SCENEorData-Hf-Scene, because linkedom keeps attribute names as written. Soincludes(SCENE_PART_ATTR)skips only pages that would have had no parts anyway.lazyPreviewImages: zero<imgstart tags already returnedhtmlthrough thetags.length !== images.lengthcheck, so returning early gives the same output.hasBaseElement: I compared old (linkedom) against new (findStartTags) on 17 edge cases:<base>in title, textarea, noscript, iframe, svg, plaintext, an attribute value, a comment, style, script, nested<template>, upper case, and<base/>. They differ only on obsolete<xmp>, where the scanner reports a<base>and linkedom correctly does not. Not worth gating on.- Both callers checked:
preview.ts:466andsubComposition.ts:341, which passes a head fragment. - This is a perf change, not a fix, so the
fails without the fix:rule does not apply.
Contributor
Merged
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three studio preview steps skip their whole-page parse when a cheap tag scan already gives the answer:
hasBaseElementasks the existing start-tag scanner (findStartTags) for a<base>instead of parsing the page.lazyPreviewImagesreturns early when the scanner finds no<img>.addScenePartsManifestreturns early when the page never mentionsdata-hf-scene.Why
The studio's preview build runs in the server process and parses the whole page in one step after another. On a large page each parse is a few hundred milliseconds, all of it blocking that process. These three steps parse only to look something up, and on most pages the lookup comes back empty.
Whole preview request for a stamped page with a 20,000-path inline SVG (about 1.4 MB), median of 5 runs on the same machine:
ensureHfIdsskips its parse)Related work
Follows #7069 (merged). Together they take a stamped page's preview build from 5 whole-page parses to 1. The one left is the read-tracking walk (
recordPreviewReferences), which needs every element's decoded attributes. The bundler's own parses are separate work.How
findStartTagsalready skips comments, raw text and<template>contents, as linkedom'squerySelectordoes;hasBaseElement's existing tests (a<base>inside a script, a comment, a template,<basefont>, upper case) pass unchanged.lazyPreviewImagesalready counted<img>start tags to line them up with the DOM's images; the count now runs first, and zero means nothing to mark.addScenePartsManifestmatched[data-hf-scene], which only finds the lowercase attribute, so a page whose text lacks that string has no parts and came back unchanged; it now comes back unchanged without the parse.Test plan
preview.parseCount.test.tscounts whole-page parses in one preview request for a stamped page with no images,<base>or scene parts: 1 (it was 4 on perf(parsers): ensureHfIds skips the parse when every element already has its id #7069's head).tscpass.Size
About 70 lines, most of it the test. The bundler's parses are a separate change in another package.